<template>
  <div class="container">
    <div class="app-container">
      <el-button class="btn-add" size="mini" type="primary" @click="dialogVisible=true">添加权限</el-button>
      <el-table :data="list" row-key="id">
        <el-table-column prop="name" label="名称" />
        <el-table-column prop="code" label="标识" />
        <el-table-column prop="description" label="描述" />
        <el-table-column label="操作">
          <template v-slot="{ row }">
            <el-button v-if="row.type===1" size="mini" type="text" @click="add(row)">添加</el-button>
            <el-button size="mini" type="text" @click="redact(row)">编辑</el-button>
            <el-button size="mini" type="text" @click="del(row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
import { postPermission, putPermission } from '@/api/permission'
export default {
  name: 'Permission',
  data() {
    return {
      list: [],
      dialogVisible: false,
      faomData: {
        name: '', // 权限点名字
        code: '', // 权限点标识
        description: '', // 权限点描述
        enVisible: 0, // 权限点开启状态,
        type: 0,
        pid: 0
      }
    }
  },
  methods: {
    // 确定
    async confirm() {
      // 表单校验
      this.$refs.faomData.validate()
      if (this.title === '编辑权限点') {
        await putPermission(this.faomData)
        // 提示用户
        this.$message.success('编辑成功')
      } else if (this.title === '新增权限点') {
        // 发送请求
        await postPermission(this.faomData)
        // 提示用户
        this.$message.success('新增成功')
      }
      // 关闭弹窗
      this.dialogVisible = false
      // 清空表单
      this.$refs.faomData.resetFields()
      // 刷新页面
      this.getPermission()
    },
    add(row) {
      // 开启弹窗
      this.dialogVisible = true
      this.faomData.pid = row.id
      // this.faomData.type = row.type
      // 清空表单
      this.$refs.faomData.resetFields()
    }
  }
}
</script>

